from threading import RLock

singleLock = RLock()


def singleton(cls):
    def wrapper(*args, **kwargs):
        with singleLock:
            if not hasattr(cls, 'instance'):
                cls.instance = cls(*args, **kwargs)
        return cls.instance

    return wrapper
